package com.shuke.my_test.shardingSphere.controller;


import com.shuke.my_test.shardingSphere.domain.UserInfo;
import com.shuke.my_test.shardingSphere.service.UserInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apiguardian.api.API;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 舒克、舒克
 * @date 2025/7/25 14:45
 * @description
 */
@Tag(name = "用户信息")
@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserInfoService userInfoService;

    @Operation(summary = "添加用户")
    @GetMapping("/add")
    public void addUser() {
        UserInfo userInfo = new UserInfo();
        userInfo.setName("张三");
        userInfo.setAge(18);
        // id 是随机的
        Long id = System.currentTimeMillis();
        userInfo.setId(id);
        log.info("添加用户：{}", userInfo);
        userInfoService.addUser(userInfo);
    }

    @Operation(summary = "查询用户")
    @GetMapping("/select")
    public UserInfo selectUser(@RequestParam String id) {
       UserInfo userInfo =  userInfoService.selectUser(id);
       return userInfo;
    }
}
